package licode;

public class L73 {
    public static void setZeroes(int[][] matrix) {
        boolean[] rowZero = new boolean[matrix.length];
        boolean[] colZero = new boolean[matrix[0].length];
        for (int i=0;i<matrix.length;i++){
            for (int j=0;j<matrix[0].length;j++){
                if (matrix[i][j]==0){
                    //将i行和j列的元素都设置为0
                    rowZero[i] = true;
                    colZero[j] = true;
                }

            }
        }
        for (int i=0;i<matrix.length;i++){
            for (int j=0;j<matrix[0].length;j++){
                if (rowZero[i]==true || colZero[j]==true){
                    matrix[i][j]=0;
                }

            }
        }


    }

    public static void main(String[] args) {
        int[][] matrix = {
                {1, 0, 3},
                {4, 0, 6},
                {7, 8, 9}
        };

        // 调用算法处理矩阵
        setZeroes(matrix);

        // 输出处理后的矩阵
        for (int[] row : matrix) {
            for (int num : row) {
                System.out.print(num + " ");
            }
            System.out.println();
        }

    }



}
